package com.ald.crossex.action.user;

import com.ald.crossex.action.BaseAction;
import com.ald.crossex.dto.JqGridRequest;
import com.ald.crossex.dto.JqGridResponse;
import com.ald.crossex.dto.OrderRequest;
import com.ald.crossex.dto.OrderResponse;
import com.ald.crossex.service.OrderService;
import com.ald.crossex.util.Page;
import com.ald.crossex.utils.PageUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Created by lishijiong on 15/1/20.
 */
@Controller
@RequestMapping(value = "/admin/order")
public class OrderAction extends BaseAction {

    @Autowired
    private OrderService orderService;

    private Logger logger = Logger.getLogger(this.getClass());

    /**
     * 获取订单列表
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public OrderResponse orderList(@RequestBody OrderRequest request) {

        OrderResponse response = new OrderResponse();

        Page page = orderService.queryCeOrders(request.getPage());

        response.setPage(page);
        return response;
    }

    @RequestMapping(value = "/finishedOrderManage")
    public String sysUserManage() {
        return "admin/order/finishedOrderManage";
    }

    @RequestMapping(value = "/unfinishOrderManage")
    public String appUserManage() {
        return "admin/order/unfinishOrderManage";
    }

    /**
     * 已完成订单
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "finishedOrderList")
    @ResponseBody
    public JqGridResponse finishOrderList(@RequestBody JqGridRequest request) {
        Page page = orderService.finishedOrder(request);
        return PageUtils.pageToJqGridResponse(page);
    }

    /**
     * 未完成订单
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "unfinishOrderList")
    @ResponseBody
    public JqGridResponse unfinishOrderList(@RequestBody JqGridRequest request) {
        Page page = orderService.unfinishOrder(request);
        return PageUtils.pageToJqGridResponse(page);
    }

}
